package com.cskaoyan.shopping.service.impl;

import com.cskaoyan.mall.commons.exception.ExceptionProcessorUtils;
import com.cskaoyan.mall.constant.ShoppingRetCode;
import com.cskaoyan.shopping.dal.persistence.ItemCatMapper;
import com.cskaoyan.shopping.dto.CategoriesResponse;
import com.cskaoyan.shopping.dto.ProductCateDto;
import com.cskaoyan.shopping.service.ICategoriesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.LinkedList;
import java.util.List;

/**
 * @ClassName: ICategoriesServiceImpl
 * @Description: 显示商品种类接口实现类
 * @Author:YPS
 * @Date: 2022/5/19 17:04
 * @Version: 1.0
 **/
@Service
@Transactional
public class ICategoriesServiceImpl implements ICategoriesService {

    @Autowired
    ItemCatMapper catMapper;

    @Override
    public CategoriesResponse showAllProducts() {
        CategoriesResponse response = new CategoriesResponse();
        try {
            List<ProductCateDto> productCateDtos = catMapper.queryAllProduct();
            response.setProductCateDtoList(productCateDtos);
            response.setCode(ShoppingRetCode.SUCCESS.getCode());
            response.setMsg(ShoppingRetCode.SUCCESS.getMessage());
        } catch (Exception e) {
            ExceptionProcessorUtils.wrapperHandlerException(response, e);
        }
        return response;
    }
}
